package com.yulongtian.oneProblemEveryDay.month202303;

/**
 * https://leetcode.cn/problems/li-wu-de-zui-da-jie-zhi-lcof/
 *可
 * @author yulongTian
 * @create 2023-03-08 10:25
 */
public class Test06 {
    public static void main(String[] args) {

    }

    public int maxValue(int[][] grid) {
        int m = grid.length;
        int n = grid[0].length;
        //第一行
        for (int i = 1; i < n; i++) {
            grid[0][i] += grid[0][i - 1];
        }
        //剩下的行
        for (int i = 1; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if (j == 0) {
                    grid[i][j] += grid[i - 1][j];
                } else {
                    grid[i][j] = Math.max(grid[i][j] + grid[i - 1][j], grid[i][j] + grid[i][j - 1]);
                }
            }
        }

        return grid[m-1][n-1];
    }

}
